﻿using ERP.Common.Util;
using System.Net;
using ERP.Common.Util.Util.Controller;
using ERP.SYS.Interfaces;
using ERP.SYS.Model.Entity;
using Microsoft.AspNetCore.Mvc;
using ERP.SYS.Model.VO;
using ERP.Common.Util.Util.Model;

namespace ERP.SYS.Controller;

[Route("api/[controller]")]
[ApiController]
public class RoleController : BaseController<SysRole>   
{
    public RoleController(IRoleService baseService) : base(baseService) { }

    [HttpGet("load/menu")]
    public async Task<IActionResult> LoadMenuByRoleId()
    {
        string authorization = Request.Headers["Authorization"];
        Dictionary<string, object> data = JwtUtil.ParseJwtMetadata(authorization);
        int roleId = int.Parse(data["roleId"].ToString());

        if (roleId == 0)
        {
            return BadRequest("role id not found");
        }

        List<MenuVO> menus = await ((IRoleService)_baseService).LoadMenuByRoleId(roleId);



        return Ok(RestResultBuilder<List<MenuVO>>.Success(menus));
    }
}
